package com.yzr.common.thread;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListTest {
    public static void main(String[] args) {
        List<String> strings = new CopyOnWriteArrayList<>();
        for (int i = 1; i <= 10; i++) {
            new Thread(() -> {
                strings.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(strings.toString());
            }, String.valueOf(i)).start();
        }

    }
}

class HashMapTest {
    public static void main(String[] args) {
        Map<String, Object> hashMap = new ConcurrentHashMap<>();
        for (int i = 1; i <= 50; i++) {
            new Thread(() -> {
                hashMap.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0, 5));
                System.out.println(hashMap);
            }, String.valueOf(i)).start();
        }
    }
}
